import Vue from "vue";
import Router from "vue-router";
import index from "@/views/index/index";
import store from "@/store";
import { Message, MessageBox } from "element-ui";
Vue.use(Router);
const originalPush = Router.prototype.push;

Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const router = new Router({
  routes: [
    {
      path: "/",
      name: "main",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views/index/bigIndex"], resolve)
    },
    {
      path: "/index/bigSearch",
      name: "bigSearch",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views/index/bigSearch"], resolve)
    },
    {
      path: "/my/bbcz/doorSeenHistory",
      name: "doorSeenHistory",
      // redirect: '/index/bigIndex',
      component: resolve =>
        require(["@/views//my/bbcz/doorseenHistory"], resolve)
    },
    {
      path: "/index/userDetail",
      name: "userDetail",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views//index/userDetail"], resolve)
    },
    {
      path: "/invite/index",
      name: "inviteIndex",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views/invite/index"], resolve)
    },
    {
      path: "/invite/resumeMoban",
      name: "inviteResumeMoban",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views/invite/resumeMoban"], resolve)
    },
    {
      path: "/my/beFondOf",
      name: "myBeFondOf",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views/invite/my/beFondOf"], resolve)
    },
    
    {
      path: "/my/blockList",
      name: "inviteBlockList",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views/invite/my/blockList"], resolve)
    },
    {
      path: "/my/inviteManage",
      name: "inviteManage",
      component: resolve => require(["@/views/invite/my/inviteManage"], resolve)
    },
    {
      path: "/invite/invite",
      name: "inviteInvite",
      // redirect: '/index/bigIndex',
      component: resolve => require(["@/views/invite/invite"], resolve)
    },
    {
      path: "/invite/inviteTime",
      name: "inviteTimeinviteTime",
      component: resolve => require(["@/views/invite/inviteTime"], resolve)
    },
    {
      path: "/invite/release",
      name: "inviteRelease",
      component: resolve => require(["@/views/invite/release/release"], resolve)
    },
    {
      path: "/invite/company",
      name: "inviteCompany",
      component: resolve => require(["@/views/invite/company"], resolve)
    },

    {
      path: "/invite/invitedetail",
      name: "invitedetail",
      component: resolve => require(["@/views/invite/invitedetail"], resolve)
    },

    {
      path: "/invite/resume",
      name: "inviteResume",
      component: resolve => require(["@/views/invite/resume"], resolve)
    },
    {
      path: "/invite/resumeOne",
      name: "inviteResumeOne",
      component: resolve => require(["@/views/invite/resumeOne"], resolve)
    },
    {
      path: "/invite/jobFairs",
      name: "inviteJobFairs",
      component: resolve => require(["@/views/invite/jobFairs"], resolve)
    },
    {
      path: "/invite/jobFairsOne",
      name: "inviteJobFairsOne",
      component: resolve => require(["@/views/invite/jobFairsOne"], resolve)
    },

    {
      path: "/test",
      name: "test",
      component: resolve => require(["@/views/test"], resolve)
    },
    {
      path: "/test2",
      name: "test2",
      component: resolve => require(["@/views/test2"], resolve)
    },
    {
      path: "/test3",
      name: "test3",
      component: resolve => require(["@/views/test3"], resolve)
    },
    {
      path: "/test4",
      name: "test4",
      component: resolve => require(["@/views/test4"], resolve)
    },
    {
      path: "/my/membershipManagement",
      name: "shareCar",
      component: resolve =>
        require(["@/views/my/bbcz/membershipManagement"], resolve)
    },
    {
      path: "/my/bbcz/shareCar",
      name: "shareCar",
      component: resolve => require(["@/views/my/bbcz/shareCar"], resolve)
    },
    {
      path: "/my/bbcz/stat",
      name: "bbczStat",
      component: resolve => require(["@/views/my/bbcz/stat"], resolve)
    },
    {
      path: "/my/bbcz/loanCalculator",
      name: "loanCalculator",
      component: resolve => require(["@/views/my/bbcz/loanCalculator"], resolve)
    },
    {
      path: "/index/bigIndex",
      name: "bigIndex",
      component: resolve => require(["@/views/index/bigIndex"], resolve)
    },
    {
      path: "/index",
      name: "index",
      component: index
    },
    {
      path: "/index/helpOwner",
      name: "helpOwner",
      component: resolve => require(["@/views/index/helpOwner"], resolve)
    },
    {
      path: "/index/optionsAvailable",
      name: "optionsAvailable",
      component: resolve => require(["@/views/index/optionsAvailable"], resolve)
    },
    {
      path: "/index/newSource",
      name: "newSource",
      component: resolve => require(["@/views/index/newSource"], resolve)
    },
    {
      path: "/index/newSourceDetails",
      name: "newSourceDetails",
      component: resolve => require(["@/views/index/newSourceDetails"], resolve)
    },
    {
      path: "/index/dealer",
      name: "dealer",
      component: resolve => require(["@/views/index/dealer"], resolve)
    },
    {
      path: "/index/newDealer",
      name: "newDealer",
      component: resolve => require(["@/views/index/newDealer"], resolve)
    },
    {
      path: "/index/newDealerDetails",
      name: "newDealerDetails",
      component: resolve => require(["@/views/index/newDealerDetails"], resolve)
    },
    {
      path: "/index/goldConsultant",
      name: "goldConsultant",
      component: resolve => require(["@/views/index/goldConsultant"], resolve)
    },
    {
      path: "/index/ownerService",
      name: "ownerService",
      component: resolve => require(["@/views/index/ownerService"], resolve)
    },
    {
      path: "/index/ownerServiceDetails",
      name: "ownerServiceDetails",
      component: resolve =>
        require(["@/views/index/ownerServiceDetails"], resolve)
    },
    {
      path: "/index/serviceDetails",
      name: "serviceDetails",
      component: resolve => require(["@/views/index/serviceDetails"], resolve)
    },
    {
      path: "/index/newOwnerService",
      name: "newOwnerService",
      component: resolve => require(["@/views/index/newOwnerService"], resolve)
    },
    {
      path: "/index/mapCar",
      name: "mapCar",
      component: resolve => require(["@/views/index/mapCar"], resolve)
    },
    {
      path: "/index/friendsCircle",
      name: "friendsCircle",
      component: resolve => require(["@/views/index/friendsCircle"], resolve)
    },
    {
      // 服务项目
      path: "/release/servicesAvailable",
      name: "servicesAvailable",
      component: resolve =>
        require(["@/views/release/servicesAvailable"], resolve)
    },
    {
      path: "/release/releaseCircleFriends",
      name: "releaseCircleFriends",
      component: resolve =>
        require(["@/views/release/releaseCircleFriends"], resolve)
    },
    {
      path: "/my/releaseOptions",
      name: "releaseOptions",
      component: resolve => require(["@/views/my/releaseOptions"], resolve)
    },
    {
      path: "/release/sellCar",
      name: "sellCar",
      component: resolve => require(["@/views/release/sellCar"], resolve)
    },
    {
      path: "/my/bbcz/allOptions",
      name: "allOptions",
      component: resolve => require(["@/views/my/bbcz/allOptions"], resolve)
    },
    {
      path: "/my/bbcz/bbczbroker",
      name: "bbczbroker",
      component: resolve => require(["@/views/my/bbcz/bbczbroker"], resolve)
    },
    {
      path: "/my/bbcz/bbczpersonal",
      name: "bbczpersonal",
      component: resolve => require(["@/views/my/bbcz/bbczpersonal"], resolve)
    },
    {
      path: "/my/bbcz/myHomepage",
      name: "myHomepage",
      component: resolve => require(["@/views/my/bbcz/myHomepage"], resolve)
    },
    {
      path: "/my/bbcz/collectgz",
      name: "collectgz",
      component: resolve => require(["@/views/my/bbcz/collectgz"], resolve)
    },
    {
      path: "/my/bbcz/historyCZ",
      name: "historyCZ",
      component: resolve => require(["@/views/my/bbcz/historyCZ"], resolve)
    },
    {
      path: "/my/bbcz/reportManagement",
      name: "reportManagement",
      component: resolve =>
        require(["@/views/my/bbcz/reportManagement"], resolve)
    },
    {
      path: "/my/bbcz/problemFeedback",
      name: "problemFeedback",
      component: resolve =>
        require(["@/views/my/bbcz/problemFeedback"], resolve)
    },
    {
      path: "/my/bbcz/doorSeen",
      name: "doorSeen",
      component: resolve => require(["@/views/my/bbcz/doorSeen"], resolve)
    },
    {
      path: "/my/bbcz/wdRelease",
      name: "wdRelease",
      component: resolve => require(["@/views/my/bbcz/wdRelease"], resolve)
    },
    {
      path: "/my/bbcz/personalHous",
      name: "personalHous",
      component: resolve => require(["@/views/my/bbcz/personalHous"], resolve)
    },
    {
      path: "/my/bbcz/commissionAssessment",
      name: "commissionAssessment",
      component: resolve =>
        require(["@/views/my/bbcz/commissionAssessment"], resolve)
    },
    {
      path: "/my/bbcz/commissionRental",
      name: "commissionRental",
      component: resolve =>
        require(["@/views/my/bbcz/commissionRental"], resolve)
    },
    {
      path: "/my/friendsCircleDetails",
      name: "friendsCircleDetails",
      component: resolve =>
        require(["@/views/my/friendsCircleDetails"], resolve)
    },
    {
      path: "/my/bbcz/myToolCz",
      name: "myToolCz",
      component: resolve => require(["@/views/my/bbcz/myToolCz"], resolve)
    },
    {
      path: "/release/certificationBroker",
      name: "certificationBroker",
      component: resolve =>
        require(["@/views/release/certificationBroker"], resolve)
    },
    {
      // 商家认证
      path: "/release/peakfirerz",
      name: "peakfirerz",
      component: resolve => require(["@/views/release/peakfirerz"], resolve)
    },
    {
      path: "/index/vehicleSeach",
      name: "vehicleSeach",
      component: resolve => require(["@/views/index/vehicleSeach"], resolve)
    },
    {
      path: "/release/sell",
      name: "sell",
      component: resolve => require(["@/views/release/sell"], resolve)
    },
    {
      path: "/release/rent",
      name: "sell",
      component: resolve => require(["@/views/release/rent"], resolve)
    },
    {
      path: "/my/issue",
      name: "issue",
      component: resolve => require(["@/views/my/issue"], resolve)
    },
    {
      path: "/my/collect",
      name: "collect",
      component: resolve => require(["@/views/my/collect"], resolve)
    },
    {
      path: "/my/inform",
      name: "inform",
      component: resolve => require(["@/views/my/inform"], resolve)
    },
    {
      path: "/my/perHouse",
      name: "perHouse",
      component: resolve => require(["@/views/my/perHouse"], resolve)
    },
    {
      path: "/index/inform",
      name: "inform",
      component: resolve => require(["@/views/index/inform"], resolve)
    },
    {
      path: "/my/browsing",
      name: "browsing",
      component: resolve => require(["@/views/my/browsing"], resolve)
    },
    {
      path: "/my/personal",
      name: "personal",
      component: resolve => require(["@/views/my/personal"], resolve)
    },
    {
      path: "/my/instrument",
      name: "instrument",
      component: resolve => require(["@/views/my/instrument"], resolve)
    },
    {
      path: "/my/broker",
      name: "broker",
      component: resolve => require(["@/views/my/broker"], resolve)
    },
    {
      path: "/my/information",
      name: "information",
      component: resolve => require(["@/views/my/information"], resolve)
    },
    {
      path: "/my/release/sell",
      name: "releaseSell",
      component: resolve => require(["@/views/my/release/sell"], resolve)
    },
    {
      path: "/my/release/rent",
      name: "releaseRent",
      component: resolve => require(["@/views/my/release/rent"], resolve)
    },
    {
      path: "/my/myCertification",
      name: "myCertification",
      component: resolve => require(["@/views/my/myCertification"], resolve)
    },
    {
      path: "/my/premises",
      name: "premises",
      component: resolve => require(["@/views/my/premises"], resolve)
    },
    {
      path: "/my/premises2",
      name: "premises2",
      component: resolve => require(["@/views/my/premises2"], resolve)
    },
    {
      path: "/my/index",
      name: "index",
      component: resolve => require(["@/views/my/index"], resolve)
    },
    {
      path: "/index/watching",
      name: "watching",
      component: resolve => require(["@/views/index/watching"], resolve)
    },
    {
      path: "/index/demo",
      name: "demo",
      component: resolve => require(["@/views/index/demo"], resolve)
    },
    {
      path: "/index/housing",
      name: "housing",
      component: resolve => require(["@/views/index/housing"], resolve)
    },
    {
      path: "/index/lease",
      name: "lease",
      component: resolve => require(["@/views/index/lease"], resolve)
    },
    {
      path: "/index/leaseDetails",
      name: "leaseDetails",
      component: resolve => require(["@/views/index/leaseDetails"], resolve)
    },
    {
      path: "/index/leaseDetailsCopy",
      name: "leaseDetailsCopy",
      component: resolve => require(["@/views/index/leaseDetailsCopy"], resolve)
    },
    {
      path: "/index/newHouse",
      name: "newHouse",
      component: resolve => require(["@/views/index/newHouse"], resolve)
    },
    {
      path: "/index/newHouseDetails",
      name: "newHouseDetails",
      component: resolve => require(["@/views/index/newHouseDetails"], resolve)
    },
    {
      path: "/index/shareHouseDetails",
      name: "shareHouseDetails",
      component: resolve =>
        require(["@/views/index/shareHouseDetails"], resolve)
    },
    {
      path: "/index/shareHouseDetailsLease",
      name: "shareHouseDetailsLease",
      component: resolve =>
        require(["@/views/index/shareHouseDetailsLease"], resolve)
    },
    {
      path: "/index/newHouseDetailsCopy",
      name: "newHouseDetailsCopy",
      component: resolve =>
        require(["@/views/index/newHouseDetailsCopy"], resolve)
    },
    {
      path: "/index/storey",
      name: "storey",
      component: resolve => require(["@/views/index/storey"], resolve)
    },
    {
      path: "/index/storeySeach",
      name: "storeySeach",
      component: resolve => require(["@/views/index/storeySeach"], resolve)
    },
    {
      path: "/index/storeyDetails",
      name: "storeyDetails",
      component: resolve => require(["@/views/index/storeyDetails"], resolve)
    },
    {
      path: "/index/intermediary",
      name: "intermediary",
      component: resolve => require(["@/views/index/intermediary"], resolve)
    },
    {
      path: "/index/intermediarySeach",
      name: "intermediarySeach",
      component: resolve =>
        require(["@/views/index/intermediarySeach"], resolve)
    },
    {
      path: "/index/ShopDetails",
      name: "ShopDetails",
      component: resolve => require(["@/views/index/ShopDetails"], resolve)
    },
    {
      path: "/index/brokerAttestation",
      name: "brokerAttestation",
      component: resolve =>
        require(["@/views/index/brokerAttestation"], resolve)
    },
    {
      path: "/index/merchantAttestation",
      name: "merchantAttestation",
      component: resolve =>
        require(["@/views/index/merchantAttestation"], resolve)
    },
    {
      path: "/index/particulars",
      name: "particulars",
      component: resolve => require(["@/views/index/particulars"], resolve)
    },
    {
      path: "/index/mapSearch",
      name: "mapSearch",
      component: resolve => require(["@/views/index/mapSearch"], resolve)
    },
    {
      path: "/invite/mapSearch",
      name: "inviteMapSearch",
      component: resolve => require(["@/views/invite/mapSearch"], resolve)
    },
    {
      path: "/invite/deliverResume",
      name: "deliverRusume",
      component: resolve => require(["@/views/invite/deliverRusume"], resolve)
    },
    {
      path: "/my/allhouses",
      name: "allhouses",
      component: resolve => require(["@/views/my/allhouses"], resolve)
    },
    {
      path: "/my/shareHouse",
      name: "shareHouse",
      component: resolve => require(["@/views/my/shareHouse"], resolve)
    },
    {
      path: "/my/isshouse",
      name: "isshouse",
      component: resolve => require(["@/views/my/isshouse"], resolve)
    },
    {
      path: "/my/vipCenterCopy",
      name: "vipCenterCopy",
      component: resolve => require(["@/views/my/vipCenterCopy"], resolve),
      meta: {
        keepAlive: true
      }
    },
    {
      path: "/my/vipCenter",
      name: "vipCenter",
      component: resolve => require(["@/views/my/vipCenter"], resolve),
      meta: {
        keepAlive: true
      }
    },
    {
      path: "/index/agentDetails",
      name: "agentDetails",
      component: resolve => require(["@/views/index/agentDetails"], resolve)
    },
    {
      path: "/index/houseSearch",
      name: "houseSearch",
      component: resolve => require(["@/views/index/houseSearch"], resolve)
    }
  ]
});
router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
});

router.beforeEach((to, from, next) => {
  console.log(this);
  console.log(this.reload);
  // let vue = new Vue()
  // console.log(vue.login)
  if (localStorage.getItem("userInfo")) {
    var userInfo = localStorage.getItem("userInfo");
    if (userInfo.isEnables == "0") {
      MessageBox.confirm("您的账号已被冻结，不能登陆！", "提示", {
        distinguishCancelAndClose: true,
        confirmButtonText: "去申诉",
        cancelButtonText: "退出登录"
      })
        .then(() => {
          console.log("thenthenthenthenthen==>", from.name);
          localStorage.setItem(
            "tempId",
            JSON.parse(localStorage.getItem("userInfo")).id
          );
          localStorage.removeItem("userInfo");
          localStorage.removeItem("contrastIdList");
          localStorage.removeItem("confirm");
          store.commit("setShowComplaint", true);
          // next({ name: from.name })
        })
        .catch(action => {
          console.log("actionactionactionactionaction");
          localStorage.removeItem("userInfo");
          localStorage.removeItem("contrastIdList");
          localStorage.removeItem("confirm");
          localStorage.removeItem("tempId");
          next({ name: "main" });
          location.reload();
        });
      // console.log('storestorestore', store.state);
      // localStorage.removeItem("userInfo")
      // localStorage.removeItem('contrastIdList')
      // localStorage.removeItem('confirm')
      // next({ name: 'main' })
    } else {
      // store.commit('setShowComplaint', true)
      // store.state.showComplaint = true
      // console.log('storestorestore', store.state);
      next();
    }
  } else next();

  // if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
});
export default router;
